﻿#pragma once

// 预编译头文件
#include "hzpch.h"
#include "./Hazel/Events/Event.h"
#include "./Hazel/Core/Window.h"
#include "./Hazel/Core/Layer.h"
#include "./Hazel/Core/LayerStack.h"
#include "./Hazel/Events/ApplicationEvent.h"

// 平台检测
#ifdef _WIN32
#define HZ_PLATFORM_WINDOWS
#elif defined(__APPLE__)
#define HZ_PLATFORM_MACOS
#elif defined(__linux__)
#define HZ_PLATFORM_LINUX
#else
#error "Unknown platform!"
#endif

// 对于静态库，不需要DLL导入/导出声明
// 如果将来要改为动态库，可以重新启用
#ifdef HZ_BUILD_DYNAMIC // 使用明确的动态库构建标志
#ifdef HZ_PLATFORM_WINDOWS
#ifdef HZ_BUILD_DLL
#define HAZEL_API __declspec(dllexport)
#else
#define HAZEL_API __declspec(dllimport)
#endif
#else
#define HAZEL_API
#endif
#else
// 静态库：不需要特殊声明
#define HAZEL_API
#endif

// 函数声明
extern HAZEL_API int HazelInit();

namespace Hazel
{
    class HAZEL_API Application
    {
    public:
        Application();
        virtual ~Application();

        void PushLayer(Layer *layer);
        void PushOverlay(Layer *overlay);

        inline static Application &Get() { return *s_Instance; }
        inline Window &GetWindow() { return *m_Window; }

        void Run();
        virtual void OnEvent(Event &e);

    private:
        std::unique_ptr<Window> m_Window; // 窗口句柄（第三阶段会初始化）
        bool m_Running = true;            // 控制主循环

        LayerStack m_LayerStack;

        bool OnWindowClose(WindowCloseEvent &e);
        bool OnWindowResize(WindowResizeEvent &e);

        static Application *s_Instance;
    };
    template <typename T>
    using Ref = std::shared_ptr<T>;

    template <typename T>
    using WeakRef = std::weak_ptr<T>;
    // 这个函数将由客户端（沙盒）定义
    Application *CreateApplication();
}
